from django import template

register = template.Library()

@register.filter(name='key')
def key(d,key):
    value = 0
    if type(d) == type([]) or type(d) == type({}):
        pass
    else:
        d = {}
    try:
        value = d[key]
    except KeyError:
        value = d.get(key)
    return value

